<?php
	session_start();
	if(!isset($_SESSION['user'])||$_SESSION['pos']!="Manager")
	{
		header("Location: index.php");
	}
	require_once("viewEmployeesController.php");
	$view = new viewEmployeesController;
	$result = $view->sendViewEmployeesRequest($_SESSION['user']);
	
	if((mysql_num_rows($result)*300)+200 > 800 )
		$height = (mysql_num_rows($result)*300)+200;
	else
		$height = 800;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>APO Cooperative Database System - Home</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8rc2.custom.css" />
<script type="text/javascript">
function finalize(fullname)
{
	return confirm("Are you sure you want to delete " + fullname + "?");
}
</script>
</head>
<body>
<div class="container ui-corner-all"  style="height:<?php echo $height ?>px">
	<div class="header ui-corner-top">
  <h1>APO Cooperative Database System</h1>
</div>
<div class="divider"></div>
  <div class="wrapper">
    <div class="content">
		<?php
		if($result!=false && mysql_num_rows($result)!=0)
		{
			while($row = mysql_fetch_array($result))
			{
				echo 
					"
					<table class=\"data\">
						<tr>
							<th>Name</th>
							<td>".$row['Last_name'].", ".$row['First_name']." ".$row['Middle_name']."</td>
						</tr>
						<tr>
							<th>Employee Number</th>
							<td>".$row['Emp_no']."</td>
						</tr>
						<tr>
							<th>TIN</th>
							<td>".$row['TIN']."</td>
						</tr>
						<tr>
							<th>Position</th>
							<td>".$row['Pos']."</td>
						</tr>
						<tr>
							<th>Branch</th>
							<td>".$row['Branch'].", ".$row['Branch_add']."</td>
						</tr>
						<tr>
							<th>Contact Number</th>
							<td>".$row['Contact_no']."</td>
						</tr>
						<tr>
							<th>Birthday</th>
							<td>".$row['Bday']."</td>
						</tr>
						<tr>
							<th>Age</th>
							<td>".$row['Age']."</td>
						</tr>
						<tr>
							<th>Planholders</th>
							<td>
						";
							
						$result2 = $view->sendViewEmployeePlanholdersRequest($row['Emp_no']);
						
						while($row2 = mysql_fetch_array($result2))
						{
							echo 
							$row2['First_name']." ".$row2['Last_name']."<br />";
						}
						echo 
						"</td>
						</tr>
						<tr>
						<td>
						<form action=\"\" method=\"post\">
							<input type=\"hidden\" name=\"full_name\" value=\"".$row['First_name']." ".$row['Last_name']."\" />
							<input type=\"hidden\" name=\"employee_no\" value=\"".$row['Emp_no']."\" />
							<input type=\"submit\" value=\"Edit\" />
						</form>
						<form action=\"deleteEmployeeController.php\" method=\"post\" onsubmit=\"return finalize(document.getElementById('full_name').value)\">
							<input type=\"hidden\" id=\"full_name\" value=\"".$row['First_name']." ".$row['Last_name']."\" />
							<input type=\"hidden\" name=\"employee_no\" value=\"".$row['Emp_no']."\" />
							<input type=\"submit\" value=\"Delete\" />
						</form>
						</td>
						</tr>
						</table>
						<hr/>
				";
			}
		}
		else
		{
			echo "<div class=\"ui-state-error\" style=\"width: 90%\">No employee/s</div>";
		}
		
		?>
		</div>
  </div>
  <div class="navigation ui-corner-all">
    <div class="navheader ui-corner-top"></div>
  	<div class="userstat">
		<?php
			echo "<p>You are logged in as: <br/>".$_SESSION['name']."<br/></p>";
			echo "<a href=\"\">Edit</a> your profile<br />";
			echo "<a href=\"logOut.php\">Log Out</a><br />";
		?>
    </div>
    </div>
    <div class="extra ui-corner-all">
    <div class="navheader ui-corner-top"></div>
    <div class="userstat">
    	<a href="managerpage.php">Back to profile page</a><br />
    	<a href="addEmployeeView.php">Add Employee</a><br />
        <a href="viewEmployeesView.php">View Employees</a><br />
        <a href="viewOtherEmployeesView.php">View Other Employees</a><br />
        <a href="movePlanHolderView.php">Move Planholders</a>
    </div>
    </div>
    <div class="footer ui-corner-bottom">
    <a href="#">Contact Us</a> | <a href="#">Terms of Use</a> | <a href="#">Trademarks</a> | <a href="#">Privacy Statement</a><br />
    Copyright &copy; 2009 . All Rights Reserved.
  </div>
</div>
</body>
</html>

